package cn.iocoder.yudao.module.system.service.cameraevent;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.system.controller.admin.cameraevent.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.cameraevent.CameraEventDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.system.convert.cameraevent.CameraEventConvert;
import cn.iocoder.yudao.module.system.dal.mysql.cameraevent.CameraEventMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;

/**
 * 告警异常列表 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
public class CameraEventServiceImpl implements CameraEventService {

    @Resource
    private CameraEventMapper cameraEventMapper;

    @Override
    public Long createCameraEvent(CameraEventCreateReqVO createReqVO) {
        // 插入
        CameraEventDO cameraEvent = CameraEventConvert.INSTANCE.convert(createReqVO);
        cameraEventMapper.insert(cameraEvent);
        // 返回
        return cameraEvent.getId();
    }

    @Override
    public void updateCameraEvent(CameraEventUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateCameraEventExists(updateReqVO.getId());
        // 更新
        CameraEventDO updateObj = CameraEventConvert.INSTANCE.convert(updateReqVO);
        cameraEventMapper.updateById(updateObj);
    }

    @Override
    public void deleteCameraEvent(Long id) {
        // 校验存在
        this.validateCameraEventExists(id);
        // 删除
        cameraEventMapper.deleteById(id);
    }

    private void validateCameraEventExists(Long id) {
        if (cameraEventMapper.selectById(id) == null) {
            throw exception(CAMERA_EVENT_NOT_EXISTS);
        }
    }

    @Override
    public CameraEventDO getCameraEvent(Long id) {
        return cameraEventMapper.selectById(id);
    }

    @Override
    public List<CameraEventDO> getCameraEventList(Collection<Long> ids) {
        return cameraEventMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<CameraEventDO> getCameraEventPage(CameraEventPageReqVO pageReqVO) {
        return cameraEventMapper.selectPage(pageReqVO);
    }

    @Override
    public List<CameraEventDO> getCameraEventList(CameraEventExportReqVO exportReqVO) {
        return cameraEventMapper.selectList(exportReqVO);
    }

}
